package javase.socket.net;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class GetIp {
	public static void main(String[] args) {
		try {
			Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
			while(nis.hasMoreElements()){
				NetworkInterface ni = nis.nextElement();
				if(!"eth0".equals(ni.getName())) {
					continue;
				}else{
					Enumeration<InetAddress> ias = ni.getInetAddresses();
					while(ias.hasMoreElements()){
						InetAddress ia = ias.nextElement();
						if(ia instanceof Inet6Address) continue;
						System.out.println(ia.getHostAddress());
					}
					break;
				}
			}
		} catch (SocketException e) {
			e.printStackTrace();
		}
	}
}
